/*
class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int zero = 0, ret = 0;
        for (int left = 0, right = 0; right < nums.size(); right++)
        {
            if (nums[right] == 0) zero++;
            while (zero > k)
            {
                if (nums[left] == 0)
                    zero--;
                left++;
            }
            ret = max(ret, right - left + 1);
        }
        return ret;
    }
};

class Solution {
public:
    int totalFruit(vector<int>& fruits) {
        int ret = 0, hash[100001] = { 0 };
        for (int left = 0, right = 0, kinds = 0; right < fruits.size(); right++)
        {
            if (hash[fruits[right]] == 0)
                kinds++;
            hash[fruits[right]]++;
            while (kinds > 2)
            {
                hash[fruits[left]]--;
                if (hash[fruits[left++]] == 0)
                    kinds--;
            }
            ret = max(ret, right - left + 1);
        }
        return ret;
    }
};

class Solution {
public:
    int minOperations(vector<int>& nums, int x) {
        int sum = 0, ret = -1;
        for (auto num : nums)
            sum += num;
        sum -= x;
        if (sum < 0)
            return -1;
        for (int left = 0, right = 0, target = 0; right < nums.size(); right++)
        {
            target += nums[right];
            while (target > sum)
                target -= nums[left++];
            if (target == sum)
                ret = max(ret, right - left + 1);
        }
        if (ret == -1)
            return -1;
        else
            return nums.size() - ret;
    }
};

*/